home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-portable.exe / quodlibet-3.3.0-portable / data / bin / bisect.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  3KB  |  101 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. '''Bisection algorithms.'''
  5.  
  6. def insort_right(a, x, lo = 0, hi = None):
  7.     '''Insert item x in list a, and keep it sorted assuming a is sorted.
  8.  
  9.     If x is already in a, insert it to the right of the rightmost x.
  10.  
  11.     Optional args lo (default 0) and hi (default len(a)) bound the
  12.     slice of a to be searched.
  13.     '''
  14.     if lo < 0:
  15.         raise ValueError('lo must be non-negative')
  16.     if hi is None:
  17.         hi = len(a)
  18.     while lo < hi:
  19.         mid = (lo + hi) // 2
  20.         if x < a[mid]:
  21.             hi = mid
  22.             continue
  23.         lo = mid + 1
  24.     a.insert(lo, x)
  25.  
  26. insort = insort_right
  27.  
  28. def bisect_right(a, x, lo = 0, hi = None):
  29.     '''Return the index where to insert item x in list a, assuming a is sorted.
  30.  
  31.     The return value i is such that all e in a[:i] have e <= x, and all e in
  32.     a[i:] have e > x.  So if x already appears in the list, a.insert(x) will
  33.     insert just after the rightmost x already there.
  34.  
  35.     Optional args lo (default 0) and hi (default len(a)) bound the
  36.     slice of a to be searched.
  37.     '''
  38.     if lo < 0:
  39.         raise ValueError('lo must be non-negative')
  40.     if hi is None:
  41.         hi = len(a)
  42.     while lo < hi:
  43.         mid = (lo + hi) // 2
  44.         if x < a[mid]:
  45.             hi = mid
  46.             continue
  47.         lo = mid + 1
  48.     return lo
  49.  
  50. bisect = bisect_right
  51.  
  52. def insort_left(a, x, lo = 0, hi = None):
  53.     '''Insert item x in list a, and keep it sorted assuming a is sorted.
  54.  
  55.     If x is already in a, insert it to the left of the leftmost x.
  56.  
  57.     Optional args lo (default 0) and hi (default len(a)) bound the
  58.     slice of a to be searched.
  59.     '''
  60.     if lo < 0:
  61.         raise ValueError('lo must be non-negative')
  62.     if hi is None:
  63.         hi = len(a)
  64.     while lo < hi:
  65.         mid = (lo + hi) // 2
  66.         if a[mid] < x:
  67.             lo = mid + 1
  68.             continue
  69.         hi = mid
  70.     a.insert(lo, x)
  71.  
  72.  
  73. def bisect_left(a, x, lo = 0, hi = None):
  74.     '''Return the index where to insert item x in list a, assuming a is sorted.
  75.  
  76.     The return value i is such that all e in a[:i] have e < x, and all e in
  77.     a[i:] have e >= x.  So if x already appears in the list, a.insert(x) will
  78.     insert just before the leftmost x already there.
  79.  
  80.     Optional args lo (default 0) and hi (default len(a)) bound the
  81.     slice of a to be searched.
  82.     '''
  83.     if lo < 0:
  84.         raise ValueError('lo must be non-negative')
  85.     if hi is None:
  86.         hi = len(a)
  87.     while lo < hi:
  88.         mid = (lo + hi) // 2
  89.         if a[mid] < x:
  90.             lo = mid + 1
  91.             continue
  92.         hi = mid
  93.     return lo
  94.  
  95.  
  96. try:
  97.     from _bisect import *
  98. except ImportError:
  99.     pass
  100.  
  101.